package com.example.administrator.x2picturetransliteration.Dao;

import android.content.Context;

import com.example.administrator.x2picturetransliteration.Dao.Gen.DaoMaster;
import com.example.administrator.x2picturetransliteration.Dao.Gen.DaoSession;

/**
 * 操作GreenDao的工具类
 * 2018/10/9.
 */

public class GreenDaoManager {

    private static DaoMaster mDaoMaster;
    private static DaoSession mDaoSession;
    private static volatile GreenDaoManager mInstance = null;
    private static final String DB_NAME = "Taodingding.db";

    private GreenDaoManager() {
    }

    public static void init(Context context) {
        //数据库存放在内存
        DaoMaster.DevOpenHelper devOpenHelper = new
                DaoMaster.DevOpenHelper(context, DB_NAME);
        mDaoMaster = new DaoMaster(devOpenHelper.getWritableDb());
        mDaoSession = mDaoMaster.newSession();
    }

    public static GreenDaoManager getInstance() {
        if (mInstance == null) {
            synchronized (GreenDaoManager.class) {
                if (mInstance == null) {
                    mInstance = new GreenDaoManager();
                }
            }
        }
        return mInstance;
    }

    public DaoSession getSession() {
        return mDaoSession;
    }

}
